<!--  -->
<template>
  <div id="main">

    <h2>代理人管理</h2>

    <el-button type="primary" style="margin:20px" @click="handleOpen('添加代理人',1)">添加代理人</el-button>

    <div class="tab">
      <el-tabs v-model="activeName">
        <el-tab-pane label="代理人" name="first">
          <div id="search-card">
            <div id="search-content">
              <el-form v-model="search" :inline="true">

                <el-form-item label="">
                  <el-input v-model="search.realName" />
                </el-form-item>

                <el-form-item>
                  <el-button type="primary" style="margin-left:10px" @click="conditionQuery">查找</el-button>
                  <el-button icon="el-icon-refresh" circle @click="fetchData()" />
                </el-form-item>

              </el-form>
            </div>

          </div>

          <div id="table-area">
            <el-table
              v-loading="listLoading"
              :data="list.slice((currentPage-1)*pagesize,currentPage*pagesize)"
              element-loading-text="Loading"
              border
              fit
              highlight-current-row
            >

              <el-table-column
                label="序号"
                type="index"
                width="80"
                align="center"
              >
                <template scope="scope">
                  <span>{{ (currentPage - 1) * pagesize + scope.$index + 1 }}</span>
                </template>
              </el-table-column>

              <el-table-column
                align="center"
                prop="consoleRealName"
                label="姓名"
              />

              <el-table-column
                align="center"
                prop="LeaderRealName"
                label="直辖代理人"
              />

              <el-table-column
                align="center"
                prop="consoleUserGroup"
                label="用户角色"
              >
                <template slot-scope="Scope">
                  <span v-if="Scope.row.consoleUserGroup==1">系统管理员</span>
                  <span v-if="Scope.row.consoleUserGroup==2">代理人</span>
                  <span v-if="Scope.row.consoleUserGroup==3">机构管理员</span>
                  <span v-if="Scope.row.consoleUserGroup==4">分支机构管理员</span>
                </template>
              </el-table-column>

              <el-table-column align="center" label="操作">
                <template slot-scope="Scope">
                  <el-button v-if="Scope.row.consoleUserGroup==2" type="primary" icon="el-icon-edit" @click="resetPwd(Scope.row.consoleUserId)">重置密码</el-button>
                  <el-button type="primary" icon="el-icon-edit" @click="handleOpen('修改管理员用户',2,Scope.row.consoleUserId)">编辑</el-button>
                  <el-button v-if="Scope.row.consoleOperationStatus==0" type="danger" icon="el-icon-delete" disabled>删除</el-button>
                  <el-button v-else type="danger" icon="el-icon-delete" @click="handleDelete(Scope.row.consoleUserId,Scope.row.consoleRealName)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>

            <div id="pages">
              <el-pagination
                :current-page="currentPage"
                :page-sizes="[5,10]"
                :page-size="pagesize"
                layout="total, sizes,prev, pager, next"
                :total="list.length"
                prev-text="上一页"
                next-text="下一页"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
              />
            </div>
          </div>
        </el-tab-pane>
        <el-tab-pane label="代理人审核" name="second">
          <div id="search-card">
            <div id="search-content">
              <el-form :inline="true">

                <el-form-item label="">
                  <el-input v-model="searchName" />
                </el-form-item>

                <el-form-item>
                  <el-button type="primary" style="margin-left:10px" @click="conditionQuery2">查找</el-button>
                  <el-button icon="el-icon-refresh" circle @click="fetchData()" />
                </el-form-item>

              </el-form>
            </div>

          </div>
          <div id="table-area">
            <el-table
              v-loading="listLoading"
              :data="list2.slice((currentPage2-1)*pagesize2,currentPage2*pagesize2)"
              element-loading-text="Loading"
              border
              fit
              highlight-current-row
            >

              <el-table-column
                label="序号"
                type="index"
                width="80"
                align="center"
              >
                <template scope="scope">
                  <span>{{ (currentPage2 - 1) * pagesize2 + scope.$index + 1 }}</span>
                </template>
              </el-table-column>

              <el-table-column
                align="center"
                prop="realname"
                label="姓名"
              />

              <el-table-column
                align="center"
                prop="consoleUser.realname"
                label="直辖代理人"
              />

              <el-table-column
                align="center"
                prop="agentAuditOperation"
                label="操作"
              >
                <template slot-scope="Scope">
                  <span v-if="Scope.row.agentAuditOperation==0">删除</span>
                  <span v-if="Scope.row.agentAuditOperation==1">添加</span>
                </template>
              </el-table-column>

              <el-table-column
                align="center"
                prop="auditPostStatus"
                label="提交状态"
              >
                <template slot-scope="Scope">
                  <span v-if="Scope.row.auditPostStatus==0">未提交</span>
                  <span v-if="Scope.row.auditPostStatus==1">审核中</span>
                  <span v-if="Scope.row.auditPostStatus==2" style="color: green;">已通过</span>
                  <span v-if="Scope.row.auditPostStatus==3" style="color: red;">已驳回</span>
                </template>
              </el-table-column>

              <el-table-column align="center" label="操作">
                <template slot-scope="Scope">
                  <el-button v-if="Scope.row.auditPostStatus==0" type="primary" icon="el-icon-edit" @click="handleOpen2('修改管理员用户',3,Scope.row.agentAuditId)">详情</el-button>
                  <el-button v-if="Scope.row.auditPostStatus!=0" type="primary" icon="el-icon-edit" @click="handleOpen2('修改管理员用户',4,Scope.row.agentAuditId)">详情</el-button>
                  <el-button v-if="Scope.row.auditPostStatus==3" type="danger" icon="el-icon-tickets" @click="seeReason(Scope.row.agentAuditId)">驳回原因</el-button>
                  <el-button v-if="Scope.row.auditPostStatus==0" type="primary" icon="el-icon-edit" @click="submit(Scope.row.agentAuditId)">提交</el-button>
                </template>
              </el-table-column>
            </el-table>

            <div id="pages">
              <el-pagination
                :current-page="currentPage2"
                :page-sizes="[5,10]"
                :page-size="pagesize2"
                layout="total, sizes,prev, pager, next"
                :total="list2.length"
                prev-text="上一页"
                next-text="下一页"
                @size-change="handleSizeChange2"
                @current-change="handleCurrentChange2"
              />
            </div>
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>
    <el-dialog title="" :close-on-click-modal="false" :visible.sync="dialogFormVisible" :before-close="handleClose">
      <el-form ref="consoleUser" :model="consoleUser" label-position="top" :rules="rules">

        <el-form-item prop="username" label="昵称" :label-width="formLabelWidth">
          <el-input
            v-model="consoleUser.username"
            autocomplete="off"
            maxlength="20"
            show-word-limit
          />
        </el-form-item>
        <el-form-item prop="realname" label="代理人姓名" :label-width="formLabelWidth">
          <el-input
            v-model="consoleUser.realname"
            autocomplete="off"
            maxlength="20"
            show-word-limit
          />
        </el-form-item>
        <el-form-item prop="userPhone" label="手机号" :label-width="formLabelWidth">
          <el-input v-model="consoleUser.userPhone" maxlength="11" autocomplete="off" onkeyup="this.value=this.value.replace(/[^\d.]/g,'');" />
        </el-form-item>
        <el-form-item prop="sex" label="性别" :label-width="formLabelWidth">
          <!-- <el-input v-model="consoleUser.sex" autocomplete="off" /> -->
          <el-radio v-model="consoleUser.sex" label="0">男</el-radio>
          <el-radio v-model="consoleUser.sex" label="1">女</el-radio>
        </el-form-item>
        <el-form-item prop="education" label="学历" :label-width="formLabelWidth">
          <el-input v-model="consoleUser.education" autocomplete="off" maxlength="20" />
        </el-form-item>
        <el-form-item prop="idcard" label="身份证号" :label-width="formLabelWidth">
          <el-input v-model="consoleUser.idcard" autocomplete="off" maxlength="18" />
        </el-form-item>
        <el-form-item prop="email" label="邮箱" :label-width="formLabelWidth">
          <el-input v-model="consoleUser.email" autocomplete="off" maxlength="32" />
        </el-form-item>
        <el-form-item prop="bankName" label="开户行" :label-width="formLabelWidth">
          <el-input v-model="consoleUser.bankName" autocomplete="off" maxlength="30" />
        </el-form-item>
        <el-form-item prop="accountName" label="户名" :label-width="formLabelWidth">
          <el-input v-model="consoleUser.accountName" autocomplete="off" maxlength="20" />
        </el-form-item>
        <el-form-item prop="accountId" label="账号" :label-width="formLabelWidth">
          <el-input v-model="consoleUser.accountId" autocomplete="off" onkeyup="this.value=this.value.replace(/[^\d.]/g,'');" maxlength="30" />
        </el-form-item>
        <!-- <el-form-item prop="agentLeader" label="是否为头领" :label-width="formLabelWidth">
          <el-radio v-model="consoleUser.agentLeader" label="1">是</el-radio>
          <el-radio v-model="consoleUser.agentLeader" label="0">否</el-radio>
        </el-form-item> -->
        <el-form-item prop="remarks" label="备注" :label-width="formLabelWidth">
          <!-- <el-input v-model="consoleUser.remarks" autocomplete="off" maxlength="20" /> -->
          <el-input v-model="consoleUser.remarks" type="textarea" :autosize="{ minRows: 5, maxRows: 100}" maxlength="4000" autocomplete="off" show-word-limit />
        </el-form-item>
        <el-form-item label="附件" :label-width="formLabelWidth">
          <el-upload
            class="upload-demo"
            name="files"
            :action="url"
            :on-preview="handlePreview"
            :on-remove="handleRemove"
            :before-remove="beforeRemove"
            multiple
            :limit="10"
            :on-exceed="handleExceed"
            :file-list="fileList"
            :on-success="handleAvatarSuccess"
          >
            <el-button size="small" type="primary">点击上传</el-button>
          </el-upload>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleClose">取 消</el-button>
        <el-button v-if="editType==3" type="primary" @click="handleUpdate2('consoleUser')">修 改</el-button>
        <el-button v-if="editType==2" type="primary" @click="handleUpdate('consoleUser')">修 改</el-button>
        <el-button v-if="editType==1" type="primary" @click="handleAddUser('consoleUser')">保 存</el-button>
      </div>
    </el-dialog>
    <el-dialog :close-on-click-modal="false" :visible.sync="refuseVisible" :before-close="handleClose2">
      <el-form label-position="top">
        <el-form-item label="驳回原因" :label-width="formLabelWidth">
          <el-input v-model="refuseReason" readonly type="textarea" :autosize="{ minRows: 5, maxRows: 100}" maxlength="4000" autocomplete="off" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleClose2">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// 例如：import 《组件名称》 from '《组件路径》';
import { getConsoleUserById, updateUser2, judgment, resetPwd, judgement, updateStatus, getLeader } from '@/api/consoleUser'
import { addAgentAuditConsoleUser, deleteAgent, getAllAgentAudit, getAgentAuditById, updateAuditPostStatus, updateAgent, searchByPostUserId } from '@/api/agentAudit'
export default {
// import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    // 这里存放数据
    var checkphone = (rule, value, callback) => {
    // let phoneReg = /(^1[3|4|5|6|7|8|9]\d{9}$)|(^09\d{8}$)/;
      if (value == null) {
        callback(new Error('请输入手机号'))
      } else if (!this.isCellPhone(value)) { // 引入methods中封装的检查手机格式的方法
        callback(new Error('请输入正确的手机号!'))
      } else {
        callback()
      }
    }
    var checkBankName = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入开户行'))
      } else if (!this.isChinese(value)) { // 引入methods中封装的检查手机格式的方法
        callback(new Error('请输入中文'))
      } else {
        callback()
      }
    }
    var checkAccountName = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入户名'))
      } else if (!this.isChinese(value)) { // 引入methods中封装的检查手机格式的方法
        callback(new Error('请输入中文'))
      } else {
        callback()
      }
    }
    return {
      currentPage: 1, // 默认显示页面为1
      pagesize: 5, //    每页的数据条数
      currentPage2: 1, // 默认显示页面为1
      pagesize2: 5, //    每页的数据条数
      url: process.env.VUE_APP_BASE_API + 'file/',
      activeName: 'first',
      list2: [],
      list: [],
      list3: [],
      listLoading: false,
      dialogFormVisible: false,
      refuseVisible: false,
      org: {},
      editType: 1, // 1 添加 2 修改
      search: {},
      mohu: '',
      consoleUser: {},
      formLabelWidth: '200px',
      fileList: [],
      fileUrl: '',
      refuseReason: '',
      searchName: '',
      rules: {
        username: [{ required: true, validator: this.checkName, trigger: 'blur' }],
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }, { min: 8, max: 12, message: '密码建议在8~12位', trigger: 'blur' }],
        realname: [{ required: true, message: '请输入账号所属人', trigger: 'blur' }],
        userPhone: [{ required: true, validator: checkphone, trigger: 'blur' }],
        email: [{ required: true, validator: this.checkEmail, trigger: 'blur' }],
        bankName: [{ required: true, validator: checkBankName, trigger: 'blur' }],
        idcard: [{ required: true, message: '请输入身份证号', trigger: 'blur' }],
        accountName: [{ required: true, validator: checkAccountName, trigger: 'blur' }],
        accountId: [{ required: true, message: '请输入账号', trigger: 'blur' }]

      }
    }
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.fetchData()
  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {

  },
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {},
  // 方法集合
  methods: {
    // 每页下拉显示数据
    handleSizeChange: function(size) {
      this.pagesize = size
    },
    // 点击第几页
    handleCurrentChange: function(currentPage) {
      this.currentPage = currentPage
    },
    handleSizeChange2: function(size) {
      this.pagesize2 = size
    },
    // 点击第几页
    handleCurrentChange2: function(currentPage) {
      this.currentPage2 = currentPage
    },
    handleClick(row) {
      console.log(row)
    },
    handleRemove(file, fileList) {
      console.log('删除', fileList)
      this.fileUrl = ''
      for (var i = 0; i < fileList.length; i++) {
        this.fileUrl = this.fileUrl + fileList[i].response.obj
      }
      console.log(this.fileUrl)
    },
    handlePreview(file) {
      console.log(file)
      //   window.location.href = file.url

      window.open(file.response.obj)
    },
    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 10 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`)
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`)
    },
    handleAvatarSuccess(res, file) {
      // this.fileUrl.push({
      //   name: file.name,
      //   url: res.obj
      // })
      this.fileUrl = this.fileUrl + res.obj
      // console.log(this.consoleUser.file)
      // console.log(this.fileUrl)
    },
    fetchData() {
      this.search = {}
      this.searchName = ''
      this.listLoading = true
      getLeader().then((resp) => {
        this.list = resp.obj
        this.list3 = resp.obj
        for (var i = 0; i < this.list.length; i++) {
          if (this.list[i].LeaderRealName == null) {
            this.list[i].LeaderRealName = '无'
            this.list3[i].LeaderRealName = '无'
          }
        }
        this.listLoading = false
      })
      getAllAgentAudit().then((resp) => {
        this.list2 = resp.obj
        this.listLoading = false
      })
    },
    // handleDelete(id, username) {
    //   this.$confirm('确认删除该用户？昵称为' + username).then(() => deleteUser(id).then((data) => {
    //     this.$notify({
    //       title: '操作成功',
    //       type: 'success'
    //     })
    //     const totalPage = Math.ceil((this.list.length - 1) / this.pagesize)
    //     const page = this.currentPage > totalPage ? totalPage : this.currentPage
    //     this.currentPage = this.currentPage < 1 ? 1 : page
    //     this.fetchData()
    //   }))
    // },
    handleDelete(id, username) {
      this.$confirm('确认删除该代理人？姓名为' + username).then(() => getConsoleUserById(id).then((data) => {
        deleteAgent(data.obj).then((resp) => {
          updateStatus(id).then((resp) => {
            this.$alert('删除提交成功，审核通过后会自动删除', '提交成功', {
              confirmButtonText: '确定'
            })
            const totalPage = Math.ceil((this.list.length - 1) / this.pagesize)
            const page = this.currentPage > totalPage ? totalPage : this.currentPage
            this.currentPage = this.currentPage < 1 ? 1 : page
            this.fetchData()
          })
        })
      }))
    },
    // handleAddUser(formName) {
    //   this.$refs[formName].validate((valid) => {
    //     if (valid) {
    //       this.consoleUser.file = this.fileUrl
    //       addUser2(this.consoleUser).then((resp) => {
    //         this.$notify({
    //           title: '操作成功',
    //           type: 'success'
    //         })
    //         this.fetchData()
    //       })
    //       this.consoleUser = {}
    //       this.dialogFormVisible = false
    //       return true
    //     } else {
    //       this.$notify({
    //         title: '请正确填写',
    //         type: 'error'
    //       })
    //       return false
    //     }
    //   })
    // },
    handleAddUser(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.consoleUser.file = this.fileUrl
          addAgentAuditConsoleUser(this.consoleUser).then((resp) => {
            this.$alert('代理人信息已保存，请在确认无误后进行提交', '保存成功', {
              confirmButtonText: '确定'
            })
            this.fetchData()
          })
          this.consoleUser = {}
          this.dialogFormVisible = false
          return true
        } else {
          this.$notify({
            title: '请正确填写',
            type: 'error'
          })
          return false
        }
      })
    },
    handleOpen(title, type, id) {
      this.consoleUser = {}
      this.fileUrl = ''
      this.fileList = []
      this.dialogFormVisible = true
      this.title = title
      this.editType = type
      if (type === 2) {
        getConsoleUserById(id).then((resp) => {
          this.consoleUser = resp.obj
          this.fileUrl = this.consoleUser.file
          console.log(this.fileUrl)
          this.consoleUser.userGroup = String(this.consoleUser.userGroup)
          this.consoleUser.sex = String(this.consoleUser.sex)
          this.consoleUser.agentLeader = String(this.consoleUser.agentLeader)
          if (this.consoleUser.orgId === -1) {
            this.consoleUser.orgId = '-1'
          }
          if (resp.obj.file) { // 后台返回的文件链接
            const a = (resp.obj.file).split(';')
            a.length -= 1
            if (a.length > 0) {
              a.forEach(item => {
                var obj = {}
                const index = item.lastIndexOf('\/')
                const fileName = item.substring(index + 1, item.length) // 最后的文件名截取出来
                const response = {}
                response.obj = item + ';'
                this.$set(obj, 'name', fileName)
                this.$set(obj, 'response', response) // 修改files里面的结构（name,url）
                this.fileList.push(obj)
              })
            }
          }
        })
      }
    },
    handleOpen2(title, type, id) {
      this.consoleUser = {}
      this.fileUrl = ''
      this.fileList = []
      this.dialogFormVisible = true
      this.title = title
      this.editType = type
      if (type === 3 || type === 4) {
        getAgentAuditById(id).then((resp) => {
          this.consoleUser = resp.obj
          this.fileUrl = this.consoleUser.file
          this.consoleUser.userGroup = String(this.consoleUser.userGroup)
          this.consoleUser.sex = String(this.consoleUser.sex)
          if (resp.obj.file) { // 后台返回的文件链接
            const a = (resp.obj.file).split(';')
            a.length -= 1
            if (a.length > 0) {
              a.forEach(item => {
                var obj = {}
                const index = item.lastIndexOf('\/')
                const fileName = item.substring(index + 1, item.length) // 最后的文件名截取出来
                const response = {}
                response.obj = item + ';'
                this.$set(obj, 'name', fileName)
                this.$set(obj, 'response', response) // 修改files里面的结构（name,url）
                this.fileList.push(obj)
              })
            }
          }
        })
      }
    },
    handleClose() {
      this.dialogFormVisible = false
      this.consoleUser = {}
    },
    handleUpdate(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.consoleUser.file = this.fileUrl
          console.log(this.fileList)

          console.log(this.consoleUser.file)
          updateUser2(this.consoleUser).then((resp) => {
            this.$notify({
              title: '修改成功',
              type: 'success'
            })
            this.fetchData()
          })
          this.dialogFormVisible = false
          return true
        } else {
          this.$notify({
            title: '请正确填写',
            type: 'error'
          })
          return false
        }
      })
    },
    handleUpdate2(formName) {
      console.log(123)
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.consoleUser.file = this.fileUrl
          updateAgent(this.consoleUser).then((resp) => {
            this.$notify({
              title: '修改成功',
              type: 'success'
            })
            this.fetchData()
          })
          this.dialogFormVisible = false
          return true
        } else {
          this.$notify({
            title: '请正确填写',
            type: 'error'
          })
          return false
        }
      })
    },
    submit(id) {
      updateAuditPostStatus(id, 1).then((resp) => {
        this.$alert('提交成功，审核通过后会自动添加', '提交成功', {
          confirmButtonText: '确定'
        })
        this.fetchData()
      })
    },
    seeReason(id) {
      this.refuseVisible = true
      getAgentAuditById(id).then((resp) => {
        this.refuseReason = resp.obj.rejectionReason
      })
    },
    handleClose2() {
      this.refuseVisible = false
      this.refuseReason = ''
    },
    resetPwd(userId) {
      resetPwd(userId).then((data) => {
        this.$notify({
          title: '重置成功',
          type: 'success'
        })
        this.fetchData()
      })
    },

    conditionQuery() {
      // searchRecommend(this.search).then((data) => {
      //   this.list = []
      //   for (var i = 0; i < data.obj.length; i++) {
      //     this.list[i].consoleUser = data.obj[i]
      //   }
      //   this.currentPage = 1
      this.list = this.list3
      var arr = this.list
      this.list = []
      for (var i = 0; i < arr.length; i++) {
        if (String(arr[i].consoleRealName).indexOf(this.search.realName) >= 0) {
          this.list.push(arr[i])
        }
      }
      this.currentPage = 1
    },

    conditionQuery2() {
      searchByPostUserId(this.searchName).then((data) => {
        this.list2 = data.obj
        this.currentPage = 1
      })
    },
    // mohuQuery() {
    //   mohuSearch(this.mohu).then((data) => {
    //     this.list = data.obj
    //     this.currentPage = 1
    //   })
    // },
    isCellPhone(val) {
      if (!/^1[3456789]\d{9}$/.test(val)) {
        return false
      } else {
        return true
      }
    },
    isChinese(val) {
      if (/[^\u4E00-\u9FA5]/.test(val)) {
        return false
      } else {
        return true
      }
    },
    // 特殊字符过滤
    checkSpecificKey(str) {
      var specialKey = "[`~!#$^&*()=|{}':;',\\[\\].<>/?~！#￥……&*（）——|{}【】‘；：”“'。，、？]‘'"
      for (var i = 0; i < str.length; i++) {
        if (specialKey.indexOf(str.substr(i, 1)) !== -1) {
          return false
        }
      }
      return true
    },

    // 验证字符串
    validateFontSize(rule, value, callback) {
      if (value.length < 30) {
        callback()
      } else {
        callback(new Error('字符串长度在1-30之间'))
      }
    },

    // 验证字符串
    validateCharacter(rule, value, callback) {
      if (this.checkSpecificKey(value)) {
        callback()
      } else {
        callback(new Error('请不要输入特殊字符'))
      }
    },
    checkRtelePhone(rule, value, callback) {
      if (!value) {
        return callback(new Error('联系电话不能为空'))
      } else {
        const reg = /^(0\d{2,3}-?)?[0-9]{7,8}$/
        if (reg.test(value)) {
          callback()
        } else {
          return callback(new Error('请输入正确的联系电话'))
        }
      }
    },
    checkEmail(rule, value, callback) {
      if (!value) {
        return callback(new Error('电子邮箱不能为空'))
      } else {
        const reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/
        if (reg.test(value)) {
          callback()
        } else {
          return callback(new Error('请输入有效的电子邮箱！'))
        }
      }
    },
    onInputBlur() {

    },
    checkName(rule, value, callback) {
      if (this.editType === 1) {
        if (!value) {
          return callback(new Error('昵称不能为空'))
        } else {
          judgment(this.consoleUser.username).then((resp) => {
            if (resp.msg === '该昵称已存在！') {
              return callback(new Error('该昵称已存在！'))
            }
            if (resp.msg === '该昵称可用！') {
              callback()
            }
          })
        }
      } else if (this.editType === 2) {
        if (!value) {
          return callback(new Error('昵称不能为空'))
        } else {
          judgement(this.consoleUser.username, this.consoleUser.userId).then((resp) => {
            if (resp.msg === '该昵称已存在！') {
              return callback(new Error('该昵称已存在！'))
            }
            if (resp.msg === '该昵称可用！') {
              callback()
            }
          })
        }
      } else {
        callback()
      }
    }
  } // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style scoped>
#main{
  margin-left: 5px;
  margin-right: 5px;
}
#search-card {
  line-height: 0px;
  text-align: right;
  width: 100%;
  height: 70px;
  overflow-x: hidden;
}
.tab{
  margin-left: 10px;
  margin-right: 10px;
}
</style>
